//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),

  },
  //事件处理函数
  bindViewTap: function (e) {
    let that = this
    var obj = JSON.parse(e.detail.rawData)
    wx.setStorageSync('userInfo', obj)
    // console.log(obj)
    wx.login({
      success: res => {
        var code = res.code
        if (res.code) {
          wx.getSetting({
            success: res => {
              if (res.authSetting['scope.userInfo']) {
                wx.getUserInfo({
                  success: res => {
                    wx.showLoading({
                      title: '请稍等...',
                      mask: true
                    })
                    var iv = res.iv
                    app.post('Login/login', {
                      code: code,
                      iv: iv,
                      encryptedData: res.encryptedData
                    }).then(res => {
                      console.log(res.data);
                      wx.setStorageSync('token', res.data.result_token)
                      wx.hideLoading()
                    }).then(() => {
                      wx.navigateTo({
                        url: '/pages/chooseIdentity/chooseIdentity',
                      })
                    })
                  }
                })
              }
            }
          })
        }
      }
    })


  },
  onLoad: function (options) {

  },


})